<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>父组件中的属性值:{{name}}</h1>
        <!-- 
            @update:title 事件名字 update:title
            @click 事件名字 click
            @add 事件名字 add
        
        -->
        <!-- <demo v-bind:title="name" @update:title="name=$event"></demo> -->
        <!-- 属性双向绑定 -->
        <demo v-bind:title.sync="name" ></demo>
    </div>
    <script src="./vue.js"></script>
    <script>
        Vue.component("demo",{
            // 约定俗成，里面的属性一般不修改
            data:function(){
                return {
                    titleStr:this.title
                }
            },
            props:["title"],
            methods: {
                handleChange:function(){
                    this.titleStr = "笑一笑";
                    // 子组件需要向父组件进行传值
                    this.$emit("update:title",this.titleStr)
                }
            },
            template:`
                <div>
                    <h1>demo 组件</h1>
                    <h2>子组件中属性值：{{titleStr}}</h2>
                    <button @click="handleChange">修改属性值</button>
                </div>
            `
        })
        let vm = new Vue({
            el: "#app",
            data:{
                name:"App 名字"
            }
        })
    </script>
</body>

</html>